//
//  LSFirstListenController.m
//  听说弱点强化训练
//
//  Created by 盛超 on 2018/8/22.
//  Copyright © 2018年 盛超. All rights reserved.
//

#import "LSFirstListenController.h"
#import "LSBackButton.h"
#import "LSFirstCell.h"

@interface LSFirstListenController ()<UITableViewDataSource,UITableViewDelegate>

@end

@implementation LSFirstListenController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor blueColor];
    // Do any additional setup after loading the view.x
    UIImageView *backGroundView = [[UIImageView alloc] init];
    backGroundView.image = [UIImage imageNamed:@"大背景"];
    [self.view addSubview:backGroundView];
    [backGroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(self.view);
    }];
    
    LSBackButton *backButton = [[LSBackButton alloc] initWithFrame:CGRectMake(0, 0, 210, 30) title:@"听说能力强化训练" image:[UIImage imageNamed:@"head_set"]];
    [backButton addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addCustomItemviews:@[backButton] position:ByNavigationItemPositionModeLeft];
    
    self.tableView = [[UITableView alloc] init];
    self.tableView.scrollEnabled = NO;
    self.tableView.backgroundColor = [UIColor clearColor];
    self.tableView.rowHeight = 160*ScalesH;//(kHeight-kNavgationBar-100*ScalesH)/3;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerClass:[LSFirstCell class] forCellReuseIdentifier:@"LSFirstCell"];
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        if (@available(iOS 11.0, *)) {
            make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
            make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop);
        } else {
            make.top.equalTo(self.view).offset(kNavgationBar);
            make.bottom.equalTo(self.view);
        }
    }];
    self.tableView.tableHeaderView = [self createTableViewHeader];
    if (@available(iOS 11.0, *)) {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
}

- (UIView*)createTableViewHeader {
    
    UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kWidth, 100*ScalesH)];
    UILabel *titleLabel = [[UILabel alloc] init];//WithFrame:CGRectMake(10, 0, kWidth-20,100*ScalesH)];
    NSString *text = @"采用过关式认知训练方式,\n设置3道听力关卡,快速提升听力能力!";
    NSRange range = [text rangeOfString:@"3"];
    titleLabel.textColor = [UIColor whiteColor];
    titleLabel.font = [UIFont systemFontOfSize:15.0f];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.numberOfLines = 0;
    NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:text];
    [attr addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17.0f],NSForegroundColorAttributeName:[UIColor yellowColor]} range:range];
    titleLabel.attributedText = attr;
 
    [header addSubview:titleLabel];
    
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(header);
        make.size.mas_equalTo(CGSizeMake(250, 40));
    }];
    
    UIButton *btn = [[UIButton alloc] init];
    [btn setImage:[UIImage imageNamed:@"说明2"] forState:UIControlStateNormal];
    [header addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleLabel.mas_right).offset(2);
        make.centerY.equalTo(titleLabel.mas_centerY).offset(10);
        make.size.mas_equalTo(CGSizeMake(13, 13));
    }];
    
    return header;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self setNaviAttributeWithTranslucent:YES stateBarLightContent:YES];
}

- (void)backAction:(UIButton*)sender {
    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - tableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}

//- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
//    return ScalesH * 160;
//}

#pragma mark - tableViewDatasource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    LSFirstCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LSFirstCell"];
    cell.pushBlock = ^{
        
    };
  
    cell.dict = @{@"IndexPathRow":@(indexPath.row),
                  @"Stage":@0
                  };
    return cell;
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
